package com.kfm.product.service.impl;

import com.kfm.common.domain.entity.ProductImages;
import com.kfm.product.mapper.ProductImagesMapper;
import com.kfm.product.service.ProductImagesService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProductImagesServiceImpl implements ProductImagesService {

    @Resource
    private ProductImagesMapper productImagesMapper;

    @Override
    public int deleteByPrimaryKey(Integer imageId) {
        return productImagesMapper.deleteByPrimaryKey(imageId);
    }

    @Override
    public int insert(ProductImages record) {
        return productImagesMapper.insert(record);
    }

    @Override
    public int insertSelective(ProductImages record) {
        return productImagesMapper.insertSelective(record);
    }

    @Override
    public ProductImages selectByPrimaryKey(Integer imageId) {
        return productImagesMapper.selectByPrimaryKey(imageId);
    }

    @Override
    public int updateByPrimaryKeySelective(ProductImages record) {
        return productImagesMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(ProductImages record) {
        return productImagesMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<ProductImages> findByProductId(Integer productId) {
        return productImagesMapper.selectByProductId(productId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updatePrimary(Integer pid, Integer id) {
        int i = productImagesMapper.cancelPrimary(pid);
        return productImagesMapper.setUpPrimary(id);
    }

}
